package me.zhengjie.poemmanager.service.impl;

import lombok.RequiredArgsConstructor;
import me.zhengjie.poemPoet.service.PoemPoetService;
import me.zhengjie.poemUser.service.PoemUserService;
import me.zhengjie.poemmanager.domain.vo.QueryCriteria;
import me.zhengjie.post.service.PostService;
import me.zhengjie.poemmanager.service.QueryService;
import me.zhengjie.recitation.service.RecitationService;
import me.zhengjie.poemmanager.util.ExtractUtil;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class QueryServiceimpl implements QueryService {
    private final PoemPoetService poemPoetService;
    private final PostService postService;
    private final PoemUserService poemUserService;
    private final RecitationService recitationService;


    @Override
    public List<QueryCriteria> queryAllByTitle(String title) {
        List<QueryCriteria>qs=postService.queryByTitle(title);
        qs.addAll(poemUserService.queryByTitle(title));
        qs.addAll(poemPoetService.queryByTitle(title));
        qs.addAll(recitationService.queryByTitle(title));
        for (QueryCriteria q:qs
             ) {
            String content = ExtractUtil.extrac(q.getContent()).replaceAll("\\s*|\r|\n|\t","");
            if(content.length()>50)
                content=content.substring(0,50);
            q.setContent(content);
        }
        return qs;
    }
}
